﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Lib.CommonForm;
using CustomUIControls;

namespace AUI
{
    public partial class frmDrugTypeTreeInfo : FormBase
    {
        int _DrugTypeId = 0;

        public int DrugTypeId
        {
            get { return _DrugTypeId; }
            set { _DrugTypeId = value; }
        }

        string _DrugTypeCode;

        public string DrugTypeCode
        {
            get { return _DrugTypeCode; }
            set { _DrugTypeCode = value; }
        }

        string _DrugTypeName;

        public string DrugTypeName
        {
            get { return _DrugTypeName; }
            set { _DrugTypeName = value; }
        }

        int _ParentId = 0;
        tbl_DrugTypes_Info m_info;


        public frmDrugTypeTreeInfo(int ParentId, int DrugTypeId)
        {
            InitializeComponent();
            

            this.txtDrugTypeCode.MaxLength = tbl_DrugTypes_Length.DrugTypeCode;
            this.txtDrugTypeName.MaxLength = tbl_DrugTypes_Length.DrugTypeName;

            _listRole = tbl_RoleRight_Controller.Instance().GetInfo("LoaiThuoc");

            FormGlobals.Control_SetRequired(txtDrugTypeCode, txtDrugTypeName);

            _DrugTypeId = DrugTypeId;

            m_info = tbl_DrugTypes_Controller.Instance().GetInfo(_DrugTypeId);
            if (m_info != null)
            {
                FormGlobals.Panel_FillData(this, m_info);
                _ParentId = m_info.ParentId;
            }
            else
                _ParentId = ParentId;

            _IsLoading = false;
        }

        public override void Show_Form()
        {
            this.ShowDialog();
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            m_info = new tbl_DrugTypes_Info();
            FormGlobals.Panel_GetData(this, m_info);
            m_info.DrugTypeId = _DrugTypeId;
            m_info.ParentId = _ParentId;
            m_info.CreateUser = FormGlobals.strUserName;
            m_info.LastUser = FormGlobals.strUserName;

            txtDrugTypeCode.BackColor = SystemColors.Window;
            if (tbl_DrugTypes_Controller.Instance().IsExist(m_info))
            {
                txtDrugTypeCode.BackColor = Color.Yellow;
                FormGlobals.Message_Warning(lblDrugTypeCode.Text + UIMessage.EXIST);
                txtDrugTypeCode.Focus();
                return;
            }

            _DrugTypeId = tbl_DrugTypes_Controller.Instance().Save(m_info);
            if (_DrugTypeId > 0)
            {

                _DrugTypeCode = txtDrugTypeCode.Text;
                _DrugTypeName = txtDrugTypeName.Text;

                FormGlobals.Message_InTaskbar(UIMessage.SAVE_COMPLETE);
                _dlgResult = DialogResult.OK;
                this.Close();
            }
        }
    }
}
